// pages/rank/index.js
Page({
  data: {
    currentTab: 0,
    tabs: ["热门景点", "美食排行", "用户活跃", "商家评分"],
    rankData: {
      "热门景点": [
        { rank: 1, name: "春熙路", score: 9.5, change: "up", visitors: "12.5万", image: "/assets/img/chart/春熙路.jpg" },
        { rank: 2, name: "宽窄巷子", score: 9.2, change: "up", visitors: "8.9万", image: "/assets/img/chart/宽窄.jpg" },
        { rank: 3, name: "锦里古街", score: 9.0, change: "down", visitors: "7.2万", image: "/assets/img/chart/锦古里街.jpg" },
        { rank: 4, name: "大熊猫基地", score: 8.8, change: "up", visitors: "6.8万", image: "/assets/img/chart/大熊猫.jpg" },
        { rank: 5, name: "青城山", score: 8.6, change: "stable", visitors: "5.5万", image: "/assets/img/chart/青城山.jpg" }
      ],
      "美食排行": [
        { rank: 1, name: "老成都火锅", score: 9.3, change: "up", rating: "4.8⭐", image: "/assets/img/chart/老成都.jpg" },
        { rank: 2, name: "海底捞", score: 9.1, change: "up", rating: "4.9⭐", image: "/assets/img/chart/海底捞.jpg" },
        { rank: 3, name: "小龙坎", score: 8.9, change: "down", rating: "4.7⭐", image: "/assets/img/chart/小龙坎.jpg" },
        { rank: 4, name: "大龙燚", score: 8.7, change: "stable", rating: "4.6⭐", image: "/assets/img/chart/大龙燚.jpg" },
        { rank: 5, name: "蜀大侠", score: 8.5, change: "up", rating: "4.5⭐", image: "/assets/img/chart/蜀大侠.jpg" }
      ],
      "用户活跃": [
        { rank: 1, name: "城旅达人", score: 9850, change: "up", posts: "128篇", image: "/assets/img/chart/城旅达人.jpg" },
        { rank: 2, name: "美食推荐官", score: 8760, change: "up", posts: "95篇", image: "/assets/img/chart/老成都.jpg" },
        { rank: 3, name: "摄影爱好者", score: 7890, change: "down", posts: "87篇", image: "/assets/img/chart/摄影爱好者.jpg" },
        { rank: 4, name: "旅行者", score: 6540, change: "stable", posts: "76篇", image: "/assets/img/chart/旅行者.jpg" },
        { rank: 5, name: "本地通", score: 5430, change: "up", posts: "65篇", image: "/assets/img/chart/本地通.jpg" }
      ],
      "商家评分": [
        { rank: 1, name: "海底捞", score: 4.9, change: "up", reviews: "2.3万条", image: "/assets/img/chart/海底捞.jpg" },
        { rank: 2, name: "老成都火锅", score: 4.8, change: "up", reviews: "1.8万条", image: "/assets/img/chart/老成都.jpg" },
        { rank: 3, name: "星巴克", score: 4.7, change: "stable", reviews: "1.5万条", image: "/assets/img/chart/星巴克.jpg" },
        { rank: 4, name: "小龙坎", score: 4.6, change: "down", reviews: "1.2万条", image: "/assets/img/chart/小龙坎.jpg" },
        { rank: 5, name: "肯德基", score: 4.5, change: "up", reviews: "9800条", image: "/assets/img/chart/肯德基.jpg" }
      ]
    }
  },

  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '城市排行榜'
    })
  },

  onTabTap: function(e) {
    const index = e.currentTarget.dataset.index
    this.setData({
      currentTab: index
    })
  },

  onItemTap: function(e) {
    const item = e.currentTarget.dataset.item
    const tabName = this.data.tabs[this.data.currentTab]
    
    wx.showModal({
      title: item.name,
      content: `排名：第${item.rank}名\n评分：${item.score}\n变化：${item.change === 'up' ? '上升' : item.change === 'down' ? '下降' : '持平'}\n${this.getExtraInfo(tabName, item)}`,
      showCancel: true,
      cancelText: '关闭',
      confirmText: '查看详情',
      success: function(res) {
        if (res.confirm) {
          wx.showToast({
            title: '详情页面开发中',
            icon: 'none'
          })
        }
      }
    })
  },

  getExtraInfo: function(tabName, item) {
    switch(tabName) {
      case "热门景点":
        return `访客数：${item.visitors}`
      case "美食排行":
        return `评分：${item.rating}`
      case "用户活跃":
        return `发帖数：${item.posts}`
      case "商家评分":
        return `评价数：${item.reviews}`
      default:
        return ""
    }
  }
})
